package com.ethan.cj.ssm.dao.provider;

import org.apache.ibatis.jdbc.SQL;

import java.util.Map;

/**
 * 日志查询总条数时返回sql语句
 */
public class LogsDaoProvider {

    /**
     * 返回查询总条数的 sql语句
     * @param parameters
     * @return sql语句
     */
    public String count(Map<String, Object> parameters) {
        return new SQL() {{
            SELECT("COUNT(*)").FROM("`logs`");
            WHERE("1=1");
            final String lrunner = (String) parameters.get("lrunner");
            final String lip = (String) parameters.get("lip");
            final String loperation = (String) parameters.get("loperation");
            if (lrunner != null && !"0".equals(lrunner))
                WHERE("`lrunner` = '" + lrunner + "'");
            else if (lip != null && !"0".equals(lip) )
                WHERE("`lip` = '" + lip + "'");
            else if (loperation != null && !"".equals(loperation))
                WHERE("`loperation` LIKE '%" + loperation + "%'");
        }}.toString();
    }
}
